'''
Created on 2011-3-2
@author: bnw
'''

from stocktable import stocklist
import cx_Oracle
import os

if __name__ == '__main__':
    os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.ZHS16GBK'

    connection = cx_Oracle.connect('istock_user', 'istock_user', 'localhost:1521/orcl')
    cursor = connection.cursor()

    fpathstr = "F:/data/corpinfo.txt"
    file = open(fpathstr, 'r')

    stockid = ''
    stockname = ''
    stocktype = ''
    starttime = ''
    belongto = ''
    startprice = ''
    for line in file:
        if line!= None and line != '':
            words = line.split()
            stockid = words[0]
            stockname = words[1]
            stocktype = words[2]
            starttime = words[3]
            belongto = words[4]
            startprice = words[5]
            sql = ("insert into STOCK_INFO_DETAIL (id, stock_id, stock_name, stock_type, first_date, belong_to, price) values(SEQUENCE_STOCK_INFO_DETAIL.NEXTVAL," + "'"+stockid+"', '" + stockname + "','" + stocktype + "','" + starttime+ "','" + belongto + "','" + startprice + "')")
            cursor.execute(sql)  
##    cursor.execute("select * from STOCK_INFO where id = 11") 
##    rows = cursor.fetchall()
##    print rows[0][2]
    connection.commit()
    cursor.close()
    connection.close()
    file.close()
    
    

    
